﻿using phhui;
using System;
using System.IO;
using System.Windows.Forms;
using System.Xml;

namespace PQBlog
{
    public partial class Login : Form
    {
        private XmlHelper xml;
        public Login()
        {
            InitializeComponent();
        }

        private void Login_Load(object sender, EventArgs e)
        {
            xml = new XmlHelper();
        }

        private void Login_Activated(object sender, EventArgs e)
        {
            if (!File.Exists("db/install"))
            {
                this.Hide();
                WinMgr.self.showInstall();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            XmlElement xnusn = (XmlElement)xml.GetXmlNodeByXpath("db/info.xml", "data//account");
            XmlElement xnpwd = (XmlElement)xml.GetXmlNodeByXpath("db/info.xml", "data//pwd");
            if (tb_usn.Text.Trim() == xnusn.InnerText&& MD6.Encryption(tb_pwd.Text.Trim())==xnpwd.InnerText)
            {
                DbMgr.hasLogin = true;
                this.Hide();
                WinMgr.self.showMain();
            }
            else
            {
                lb_tip.Text = "账号或密码错误！";
            }
        }

        private void Login_FormClosed(object sender, FormClosedEventArgs e)
        {
            WinMgr.self.quit();
        }
    }
}
